package com.sxkf.core.pay.wxpay.wxenum;

//import com.demo.project_template.exception.ErrorCodeException;
import lombok.AllArgsConstructor;
import lombok.Getter;
import org.jeecg.common.exception.SxkfException;

import static org.jeecg.common.exception.SxkfExceptionEnum.PAY_TYPE_ERROR;

//import static com.demo.project_template.exception.ErrorCodeExceptionEnum.PAY_TYPE_ERROR;

/**
 * @Author ZhangKeChen
 * @Date 2022/9/29
 * @Description
 */
@Getter
@AllArgsConstructor
public enum WxPayTypeEnum {
    /**
     * APP支付
     */
    APP_TYPE("APP", "https://api.mch.weixin.qq.com/v3/pay/transactions/app"),
    /**
     * JSAPI支付
     */
    JSAPI_TYPE("JSAPI", "https://api.mch.weixin.qq.com/v3/pay/transactions/jsapi"),
    /**
     * H5支付
     */
    H5_TYPE("H5", "https://api.mch.weixin.qq.com/v3/pay/transactions/h5"),
    /**
     * NATIVE支付
     */
    NATIVE_TYPE("NATIVE", "https://api.mch.weixin.qq.com/v3/pay/transactions/native");
    private String payType;
    private String payUrl;

    /**
     * 通过枚举的key，获取value
     * @param key
     * @return
     */
    public static String getNameByKey(String key) {
        WxPayTypeEnum[] payArray = values();
        for (WxPayTypeEnum channelEnum : payArray) {
            if (channelEnum.getPayType().equals(key)) {
                return channelEnum.getPayUrl();
            }
        }
        throw new SxkfException(PAY_TYPE_ERROR);
    }


}
